<?php
include_once('inc/functions.inc.php');
$db = DbManager::getMe();
if (!isEmpty(getParam('operation'))) {

    switch (getParam('operation')) {
        case 'filtro': {
                fntAcademicoCobrosCobrosFiltro($db);
                break;
            }
        case 'secciones': {
                fntAcademicoCobrosCobrosFiltroSecciones($db);
                break;
            }
        case 'contenido': {
                fntAcademicoCobrosCobrosContenido($db);
                break;
            }
        case 'contenidoDetalle': {
                fntAcademicoCobrosCobrosContenidoDetalle($db);
                break;
            }
        case 'fntShowDetalleAnulacion': {
                fntShowDetalleAnulacion();
                break;
            }
        case 'fntAnularCobro': {
                fntAnularCobro();
                break;
            }
        case 's': {
                fntAcademicoCobrosCobrosGrabar($db);
                break;
            }
    }
    die();
}

/**
 * Anula cobros 
 */
function fntAnularCobro() {
    $idCobro = getParam("idCobro");
    $bCobros = BoCobros::getMe();
    $newAjuste = $bCobros->anularCobroContable($idCobro);
    echo $newAjuste;
}

/**
 * Muestra el detalle de la anulacion
 * @param type $db 
 */
function fntShowDetalleAnulacion() {
    $idCobro = getParam("idCobro");
    $bCobros = BoCobros::getMe();
    $cobro = $bCobros->getDataCobro($idCobro);
    $ajuste = $cobro["ajuste"];
    ?>
    <div id="contenidocobrosanulacion">
        <?php echo $ajuste["html"]; ?>
        <div style="padding:5px;">
            <button type="button" onclick="javascript:fntAnularCobro(<?php echo $idCobro; ?>)">Anular</button>
        </div>
    </div>
    &nbsp;
    <?php
}

function fntAcademicoCobrosCobrosFiltro() {
    ?>
    <div style="width: 1000px; height: 30px; float: left;">&nbsp;</div>
    <div style="width: 100px; height: 30px; float: left;"><b>Estudiante</b></div>
    <div style="width: 400px; height: 30px; float: left;">
        <input type="text" name="txtAcademicoCobrosCobros_FK-ESTUDIANTE" id="txtAcademicoCobrosCobros_FK-ESTUDIANTE" value="" style="width: 300px;">
    </div>
    <div style="width: 100px; height: 30px; float: left;"><b>Benefactor</b></div>
    <div style="width: 400px; height: 30px; float: left;">
        <input type="text" name="txtAcademicoCobrosCobros_FK-BENEFACTOR" id="txtAcademicoCobrosCobros_FK-BENEFACTOR" value="" style="width: 300px;">
    </div>

    <div style="width: 500px; float: left; text-align: center;">&nbsp;</div>
    <style type="text/css">
        .ui-button { margin-left: -1px; }
        .ui-button-icon-only .ui-button-text { padding: 0.01em; } 
        .ui-autocomplete-input { margin: 0; padding: 0.0em 0 0.0em 0.0em; }
    </style> 
    <script type="text/javascript">
        $("#txtAcademicoCobrosCobros_FK-ESTUDIANTE").keyup(function(event) {
            $("#txtAcademicoCobrosCobros_FK-BENEFACTOR").val("");
            if( event.keyCode == "13" ) {
                fntAcademicoCobrosCobrosContenido();
            }
        }); 

        $("#txtAcademicoCobrosCobros_FK-BENEFACTOR").keyup( function(event) {
            $("#txtAcademicoCobrosCobros_FK-ESTUDIANTE").val("");
            if( event.keyCode == "13" ) {
                fntAcademicoCobrosCobrosContenido();
            }
        });
    </script>
    <?php
}

function fntAcademicoCobrosCobrosContenido($db) {
    $errores = array();
    $arrInfo = array();
    $strEstudianteBenefactor = isset($_POST["txtAcademicoCobrosCobros_FK-ESTUDIANTE"]) ? $_POST["txtAcademicoCobrosCobros_FK-ESTUDIANTE"] : "";
    $strEstudiante = isset($_POST["txtAcademicoCobrosCobros_FK-ESTUDIANTE"]) ? $_POST["txtAcademicoCobrosCobros_FK-ESTUDIANTE"] : "";
    $strBenefactor = isset($_POST["txtAcademicoCobrosCobros_FK-BENEFACTOR"]) ? $_POST["txtAcademicoCobrosCobros_FK-BENEFACTOR"] : "";
    $arrEstudianteBenefactor = explode("_", $strEstudianteBenefactor);
    $intID = $arrEstudianteBenefactor[0];

    $strTipo = "ESTUDIANTE";
    if (!empty($strBenefactor)) {
        $strTipo = "BENEFACTOR";
    }

    $arrMes = getMeses();
    ?>
    <br>
    <?php
    if ($strTipo == "ESTUDIANTE") {
        $intID = $strEstudiante;
        $arrInfo = array();
        $strQuery = "SELECT  E.ID AS CODIGO,
                                E.FIRST_NAME,
                                E.LAST_NAME,
                                EA.*, 
                                G.NOMBRE AS GRADO, 
                                S.NOMBRE AS SECCION
                        FROM    cllg_student AS E,
                                cllg_academico_estudiantes_asignacion AS EA,
                                cllg_academico_grados AS G,
                                cllg_academico_secciones AS S
                        WHERE   E.ID = EA.FK_ESTUDIANTE 
                        AND     EA.FK_GRADO = G.ID
                        AND     EA.FK_SECCION = S.ID
                        AND     EA.FK_ESTUDIANTE = '{$strEstudiante}'";
        $arrInfo = array("CODIGO" => "", "FIRST_NAME" => "", "LAST_NAME" => "", "GRADO" => "", "SECCION" => "");
        $r = $db->queryToArray($strQuery, true);
        foreach ($r as $row) {
            $arrInfo = $row;
        }
        if (count($arrInfo) > 0) {
            ?>
            <div id="divContenidoEstudianteDetalle" style="width: 1000px; float: left; padding: 5px;">
                <div style="width: 100px; float: left;"><b>Codigo</b></div>
                <div style="width: 900px; float: left;">&nbsp;<?php print $arrInfo["CODIGO"]; ?></div>
                <div style="width: 100px; float: left;"><b>Estudiante</b></div>
                <div style="width: 900px; float: left;">&nbsp;<?php print $arrInfo["FIRST_NAME"] . " " . $arrInfo["LAST_NAME"]; ?></div>
                <div style="width: 100px; float: left;"><b>Grado</b></div>
                <div style="width: 900px; float: left;">&nbsp;<?php print $arrInfo["GRADO"]; ?></div>
                <div style="width: 100px; float: left;"><b>Sección</b></div>
                <div style="width: 900px; float: left;">&nbsp;<?php print $arrInfo["SECCION"]; ?></div>
                <?php
                $arrInfo = array("RAZON_SOCIAL" => "", "CODIGO" => "", "RAZON_SOCIAL" => "", "NOMBRE_A" => "", "APELLIDO_A" => "");
                $strQuery = "SELECT  P.*  
                        FROM    cllg_student AS E,
                                cllg_parent AS P,
                                cllg_student_parent AS EP
                        WHERE   E.ID = EP.STUDENT
                        AND     P.ID = EP.PARENT
                        AND     E.ID = '{$strEstudiante}'";
                $qTMP = $db->query($strQuery);
                while ($rTMP = $db->fetch_array($qTMP)) {
                    $arrInfo = $rTMP;
                }
                $db->free_result($qTMP);
                ?>
                <div style="width: 100px; float: left;"><b>Padre</b></div>
                <div style="width: 900px; float: left;">&nbsp;<?php print htmlentities($arrInfo["NOMBRE_A"] . " " . $arrInfo["APELLIDO_A"]); ?></div>    
                <?php
                $arrInfo = array("RAZON_SOCIAL" => "", "CODIGO" => "", "RAZON_SOCIAL" => "");
                $strQuery = "SELECT  B.*  
                        FROM    cllg_student AS E,
                                cllg_benefactor AS B,
                                cllg_student_benefactor AS EB
                        WHERE   E.ID = EB.STUDENT
                        AND     B.ID = EB.BENEFACTOR
                        AND     E.ID = '{$strEstudiante}'";
                $qTMP = $db->query($strQuery);
                while ($rTMP = $db->fetch_array($qTMP)) {
                    $arrInfo = $rTMP;
                }
                $db->free_result($qTMP);
                ?>
                <div style="width: 100px; float: left;"><b>Benefactor</b></div>
                <div style="width: 900px; float: left;">&nbsp;<?php print $arrInfo["RAZON_SOCIAL"]; ?></div>    
            </div>
            <?php
        } else {
            $errors[] = "No existe ningun alumno con el codigo ingresado!";
        }
    } else
    if ($strTipo == "BENEFACTOR") {
        $intID = $strBenefactor;
        $strQuery = "SELECT  B.ID AS CODIGO, B.RAZON_SOCIAL 
                    FROM    cllg_benefactor AS B 
                    WHERE   B.ID = '{$strBenefactor}'";
        $qTMP = $db->query($strQuery);
        while ($rTMP = $db->fetch_array($qTMP)) {
            $arrInfo = $rTMP;
        }
        $db->free_result($qTMP);
        if (count($arrInfo) > 0) {
            ?>        
            <div style="width: 100px; float: left;"><b>Codigo</b></div>
            <div style="width: 900px; float: left;">&nbsp;<?php print $arrInfo["CODIGO"]; ?></div>
            <div style="width: 100px; float: left;"><b>Benefactor</b></div>
            <div style="width: 900px; float: left;">&nbsp;<?php print $arrInfo["RAZON_SOCIAL"]; ?></div>
            <div style="width: 1000px; float: left;"><b>Estudiantes</b></div>
            <?php
            $strQuery = "SELECT  E.* 
                    FROM    cllg_student AS E,
                            cllg_student_benefactor AS EB
                    WHERE   E.ID = EB.STUDENT
                    AND     EB.BENEFACTOR = '{$strBenefactor}'";
            $qTMP = $db->query($strQuery);
            while ($rTMP = $db->fetch_array($qTMP)) {
                ?>
                <div style="width: 1000px; float: left;">&nbsp;<?php print $rTMP["FIRST_NAME"] . " " . $rTMP["LAST_NAME"]; ?></div>
                <?php
            }
            $db->free_result($qTMP);
        } else {
            $errors[] = "No existe ningun benefactor con el codigo ingresado!";
        }
    } else {
        $errores[] = "Busqueda erronea!";
    }
    if (count($errores) <= 0) {
        ?>
        <div class="dttb" style="width: 1000px; float: left;">
            <table width="90%" cellpadding="2" cellspacing="2" border="0" style="border-collapse: collapse;">
                <thead>
                    <tr>
                        <th width="10%" align="center" ><b>Codigo de Generación</b></th>
                        <th width="60%" align="center" ><b>Descripcion</b></th>
                        <th width="15%" align="center" ><b>Tipo Cargo</b></th>
                        <th width="15%" align="center" ><b>Mes</b></th>
                        <th width="20%" align="center" ><b>Valor</b></th>
                        <th width="20%" align="center" ><input type="checkbox" id="checkAll" /></th>
                        <th width="20%" align="center" >&nbsp;</th>
                    </tr>
                </thead>
                <?php
                $strCargoTipo = "";
                if ($strTipo == "ESTUDIANTE") {
                    $strCargoTipo = "padres";
                }
                if ($strTipo == "BENEFACTOR") {
                    $strCargoTipo = "benefactores";
                }

                $strQuery = "SELECT  cllg_academico_cobros.ID, 
                    MONTH(cllg_academico_cobros.FECHA) AS MES, 
                    cllg_academico_cobros.SALDO_ACT AS VALOR, 
                    cllg_academico_cargos_detail.VIGENCIA,
                    cllg_academico_cargos_detail.DESCRIPCION
                    FROM    cllg_academico_cobros,
                            cllg_academico_cargos_detail
                    WHERE  not isnull(cllg_academico_cobros.PARTIDA_CARGOS )
                    AND cllg_academico_cobros.FK_CARGO_DETAIL_ID = cllg_academico_cargos_detail.ID
                    AND     cllg_academico_cobros.FK_ESTUDIANTE = '{$intID}'
                    AND     cllg_academico_cobros.TIPO = '{$strTipo}'
                    AND     cllg_academico_cargos_detail.TIPO = '{$strCargoTipo}'
                    AND     cllg_academico_cobros.ESTADO IN ('INGRESADO','PAGADOPARCIAL') 
                    ORDER BY MONTH(cllg_academico_cobros.FECHA),cllg_academico_cargos_detail.VIGENCIA ASC"; //patch solo para activos
                $qTMP = $db->query($strQuery);
                while ($rTMP = $db->fetch_array($qTMP)) {
                    ?>
                    <tr>
                        <td align="center" >
                            <?php print $rTMP["ID"]; ?>
                        </td>
                        <td align="rigth" >
                            <?php print $rTMP["DESCRIPCION"]; ?>
                        </td>
                        <td align="center" >
                            <?php print $rTMP["VIGENCIA"]; ?>
                        </td>
                        <td align="center" >
                            <?php print $arrMes[$rTMP["MES"]]; ?>
                        </td>
                        <td align="right" >
                            <input type="hidden" name="chkCobroAbonoOrig_<?php print $rTMP["ID"]; ?>" id="chkCobroAbonoOrig_<?php print $rTMP['ID']; ?>" 
                                   value="<?php print $rTMP["VALOR"]; ?>" />
                            <input style="text-align: right;"  type="text" readonly="readonly" name="chkCobroAbono_<?php print $rTMP["ID"]; ?>" id="chkCobroAbono_<?php print $rTMP['ID']; ?>" 
                                   value="<?php print $rTMP["VALOR"]; ?>" />
                        </td>
                        <td align="center" >
                            <input type="checkbox" name="chkCobroID_<?php print $rTMP["ID"]; ?>" value="<?php print $rTMP["ID"]; ?>" />
                        </td>
                        <td align="center" >
                            <button type="button" onclick="javascript:fntShowDetalleAnulacion(<?php print $rTMP["ID"]; ?>);" >Anular</button>
                        </td>
                    </tr>
                    <?php
                }
                $db->free_result($qTMP);
                ?>
                <tr><td align="center" >&nbsp;</td>
                    <td colspan="3" align="right" ><b>Total&nbsp;</b></td>
                    <td align="left" >
                        <input type="text" name="txtAcademicoCobrosCobrosTotal" value="0.00" style="width: 98%; text-align: right; border: none; background-color: transparent" readonly="readonly">
                    </td>
                    <td align="center" >&nbsp;</td>
                    <td align="center" >&nbsp;</td>
                </tr>
            </table>
        </div>
        <div id="windatoscobro" style="visibility: hidden;"></div>
        <div style="width: 1000px; float: left;">&nbsp;</div>
        <div class="dttb" style="width: 1000px; float: left;">&nbsp;
            <table width="90%" cellpadding="2" cellspacing="2" border="0"  id="tblAcademicoCobrosCobrosContenidoDetalle">
                <thead>
                    <tr>
                        <th width="20%" align="center" ><b>Tipo de Pago</b></th>
                        <th width="20%" align="center" ><b>Valor</b></th>
                        <th width="20%" align="center" ><b>No. Recibo</b></th>
                        <th width="20" align="center" ><b>Fecha</b></th>               
                        <th width="20" align="center" ><b>&nbsp;</b></th>               
                    </tr>
                </thead>
                <tr>
                    <td align="center" >
                        <select name="sltAcademicoCobrosCobrosTipo">
                            <option value="DEPOSITO">DEPOSITO</option>
                            <option value="EFECTIVO">EFECTIVO</option>
                            <option value="CHEQUE">CHEQUE</option>
                        </select>
                    </td>
                    <td align="center" >
                        <input type="text" name="txtAcademicoCobrosCobrosValor" value="" style="text-align: right; background-color: white; border: 1px solid #AAAAAA;" readonly="readonly">
                    </td>
                    <td align="center" ><input type="text" name="txtAcademicoCobrosCobrosNoDocumento" value=""></td>
                    <td align="center" >
                        <input type="text" id="txtAcademicoCobrosCobrosFecha" name="txtAcademicoCobrosCobrosFecha" value="" size="12" maxlength="10" style="text-align: center;" />
                    </td> 
                    <td align="center" >
                        <button id="guardarCobro" type="button">Guardar</button>
                    </td>
                </tr>
            </table>
        </div>
        <script type="text/javascript" language="javascript">
            (function($) {
                // $("input[name='txtAcademicoCobrosCobrosNoDocumento']").mask('');
                $("#txtAcademicoCobrosCobrosFecha").datepicker({
                    changeMonth: true,
                    changeYear: true,
                    monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],
                    dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
                    dateFormat: 'dd-mm-yy'
                });
                $("#guardarCobro").button();
                $("#guardarCobro").click( function () {
                    fntAcademicoCobrosCobrosGrabar();
                });
                $("#btnAcademicoCobrosCobrosAgregar").click( function () {
                    fntAcademicoCobrosCobrosAgregar();
                });
            })(jQuery);
            $("button").button();
        </script>
        <div id="divAcademicoCobrosCobrosContenidoDetalle" style="width: 1000px; float: left;">&nbsp;</div>
        <script type="text/javascript" language="javascript">
            function fntAcademicoCobrosCobrosTotal() {
                sinTotal = 0;
                $("input[name*='chkCobroID_']").each( function() {
                    if( $(this).attr("checked") ) {
                        var valOrig=$("#chkCobroAbonoOrig_"+$(this).val()).val();
                        var val=$("#chkCobroAbono_"+$(this).val()).val();
                        if(!isNaN(val)){
                            if(parseFloat(val)>parseFloat(valOrig)){ //corrige el monto
                                $("#chkCobroAbono_"+$(this).val()).val(valOrig);
                                val=valOrig;
                            }                            
                            sinTotal += val * 1;
                        }
                    }
                });
                $("input[name='txtAcademicoCobrosCobrosTotal']").val(sinTotal); 
                $("input[name='txtAcademicoCobrosCobrosValor']").val(sinTotal); 
            }
            $(function() {
                $("input[name*='chkCobroAbono_']").keyup( function() {
                    fntAcademicoCobrosCobrosTotal();    
                });
                $("input[name*='chkCobroID_']").click( function() {
                    var input=$("#chkCobroAbono_"+$(this).val());
                    input.attr("readonly",!$(this).attr("checked"));
                    fntAcademicoCobrosCobrosTotal();    
                });
                $("#checkAll").click( function() {
                    $("[name*='chkCobroID_']").attr("checked",$(this).attr("checked"));	
                    $("[name*='chkCobroAbono_']").attr("readonly",!$(this).attr("checked"));	
                    fntAcademicoCobrosCobrosTotal();                     
                });		  
                                                                                                                                               
            });
        </script>
        <?php
    } else {
        showError($errors);
    }
}

function fntAcademicoCobrosCobrosContenidoDetalle($db) {

    $intCobro = isset($_POST["radCobroID"]) ? $_POST["radCobroID"] : "";
    ?>
    <div style="width: 1000px; float: left;">&nbsp;</div>
    <div style="width: 1000px; float: left;">&nbsp;</div>
    <table width="60%" cellpadding="2" cellspacing="2" border="0" style="border-collapse: collapse;" id="tblAcademicoCobrosCobrosContenidoDetalle">
        <tr>
            <td width="20%" align="center" ><b>Tipo de Pago</b></td>
            <td width="20%" align="center" ><b>Valor</b></td>
            <td width="20%" align="center" ><b>No. Docto</b></td>
            <td width="20" align="center" ><b>Fecha</b></td>
            <td width="20" align="center" >&nbsp;</td> 
        </tr>
        <tr>
            <td align="center" >
                <select name="sltAcademicoCobrosPagoTipo">
                    <option value="DEPOSITO">DEPOSITO</option>
                    <option value="EFECTIVO">EFECTIVO</option>
                    <option value="CHEQUE">CHEQUE</option>
                </select>
            </td>
            <td align="center" >
                <input type="text" name="txtAcademicoCobrosPagoValor" value=""></td>
            <td align="center" ><input type="text" name="txtAcademicoCobrosPagoNoDocumento" value=""></td>
            <td align="center" >
                <input type="text" name="txtAcademicoCobrosPagoFecha" value="" size="12" maxlength="10" style="text-align: center;">
            </td>
            <td align="center" >
                <!--    <button disabled="disabled" name="btnAcademicoCobrosCobrosAgregar" id="btnAcademicoCobrosCobrosAgregar" type="button">Agregar</button> -->
            </td>
        </tr>
        <?php
        $strQuery = "SELECT  *
                FROM    cllg_academico_cobros_detail 
                WHERE   cllg_academico_cobros_detail.FK_COBRO_ID = '{$intCobro}' 
                AND     cllg_academico_cobros_detail.FK_AJUSTE_ANULACION = '0' ";
        $qTMP = $db->query($strQuery);
        while ($rTMP = $db->fetch_array($qTMP)) {
            ?>
            <tr>
                <td align="center" ><?php print $rTMP["TIPO"]; ?></td>
                <td align="center" ><?php print $rTMP["VALOR"]; ?></td>
                <td align="center" ><?php print $rTMP["NO_DOCUMENTO"]; ?></td>
                <td align="center" >&nbsp;</td>
                <td align="center" >&nbsp;</td>
            </tr>
            <?php
        }
        $db->free_result($qTMP);
        ?>
    </table>
    <script type="text/javascript" language="javascript">
        $(function() {
            $("input[name='txtAcademicoCobrosPagoNoDocumento']").mask('99999999999');
            $("input[name='txtAcademicoCobrosCobrosFecha']").datepicker({
                changeMonth: true,
                changeYear: true,
                monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun','Jul','Ago','Sep','Oct','Nov','Dic'],
                dayNamesMin: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
                dateFormat: 'dd-mm-yy'
            });
            $("#btnAcademicoCobrosCobrosAgregar").click( function () {
                fntAcademicoCobrosCobrosAgregar();
            });
        });
    </script>    
    <?php
}

function fntAcademicoCobrosCobrosGrabar($db) {

    $intTotal = isset($_POST["txtAcademicoCobrosCobrosTotal"]) ? floatval($_POST["txtAcademicoCobrosCobrosTotal"]) : 0;
    $usr = $_SESSION[USUARIO]["usuario"];
    $strQuery = "INSERT INTO cllg_academico_pagos (FECHA, TOTAL,USUARIO_PAGO) VALUE (NOW(), '{$intTotal}','$usr')";
    $db->query($strQuery);
    $intPagoID = mysql_insert_id($db->link_id);

    reset($_POST);
    while ($arrPost = each($_POST)) {
        $arrExplode = explode("_", $arrPost["key"]);
        if ($arrExplode[0] == "chkCobroID") {
            //$montoPago = $arrPost["value"];

            $montoPago = getParam("chkCobroAbono_" . $arrPost["value"]);
            $nuevoEstado = "PAGADO";

            //recupera informacion para evitar inputs injection and sniffering
            $cb = $db->queryToArray("select ID,FK_ESTUDIANTE,TIPO,FK_CARGO_DETAIL_ID,VALOR,SALDO_ACT,ESTADO,MONTH(FECHA) as MES from cllg_academico_cobros where ID = '{$arrExplode[1]}'");
            $cb = $cb[0];
            $cr = $db->queryToArray(sprintf("select DESCRIPCION from cllg_academico_cargos_detail where ID = %s", $cb["FK_CARGO_DETAIL_ID"]));
            $cr = $cr[0];

            $valorCobro = $cb["ESTADO"] == 'INGRESADO' ? $cb["VALOR"] : $cb["SALDO_ACT"];
            $saldoAct = $valorCobro - $montoPago;
            $saldoAnt = $cb["SALDO_ACT"];
            if ($saldoAct > 0) {
                $nuevoEstado = "PAGADOPARCIAL";
            }

            //guardo detalle del pago para cada cobro
            $db->query("INSERT INTO cllg_academico_pagos_detail 
                        (FK_PAGO_ID, FK_COBRO_ID, MONTO) 
                        VALUES 
                        ('{$intPagoID}', '{$arrExplode[1]}', '{$montoPago}')");

            $db->query("UPDATE cllg_academico_cobros SET 
                            ESTADO = '$nuevoEstado',
                            SALDO_ACT='$saldoAct',
                            SALDO_ANT='$saldoAnt' WHERE ID = '{$arrExplode[1]}'");

            $fkEstudiante = $cb["TIPO"] == "ESTUDIANTE" ? $cb["FK_ESTUDIANTE"] : -1;
            $fkBenefactor = $cb["TIPO"] == "BENEFACTOR" ? $cb["FK_ESTUDIANTE"] : -1;
            $meses = getMesesData();
            $data = array("cobro" => $cb["ID"], "fkEstudiante" => $fkEstudiante,
                "fkBenefactor" => $fkBenefactor, "value" => $montoPago,
                "debe" => $montoPago, "haber" => 0,
                "DESCRIPCION" => "Cancelacion Cargo " . $cr["DESCRIPCION"] . "-" . $meses[$cb["MES"]]);
            registerMovCta($data, $db);
        }
    }

    reset($_POST);
    $strTipo = $_POST["sltAcademicoCobrosCobrosTipo"];
    $sinMonto = $_POST["txtAcademicoCobrosCobrosValor"];
    $strNoRecibo = $_POST["txtAcademicoCobrosCobrosNoDocumento"];
    $strFecha = $_POST["txtAcademicoCobrosCobrosFecha"];
    $strFecha = implode("-", array_reverse(explode("-", $strFecha)));

    $db->query("INSERT INTO cllg_academico_pagos_formas 
				(FK_PAGO_ID, TIPO, MONTO, NO_RECIBO, FECHA) 
				VALUES 
				('{$intPagoID}', '{$strTipo}', '{$sinMonto}', '{$strNoRecibo}', '{$strFecha}')");
}
?>